package com.sctvcloud.longchang.ui.activities;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;

import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.ruihang.generalibrary.utils.ListUtils;
import com.sctvcloud.longchang.R;
import com.sctvcloud.longchang.application.Constances;
import com.sctvcloud.longchang.base.BaseActivity;
import com.sctvcloud.longchang.beans.ConvenientTelTypeBean;
import com.sctvcloud.longchang.beans.FUsers;
import com.sctvcloud.longchang.beans.NewsItem;
import com.sctvcloud.longchang.beans.TelephoneTypeVo;
import com.sctvcloud.longchang.http.AbsListNetCallback;
import com.sctvcloud.longchang.http.AbsNetCallBack;
import com.sctvcloud.longchang.http.NetUtils;
import com.sctvcloud.longchang.ui.adapter.ConvenientTelAdapter;
import com.sctvcloud.longchang.ui.utils.TitleUtils;
import com.sctvcloud.longchang.utils.ListTypeUtils;
import com.sctvcloud.longchang.utils.UserManager;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 便民电话
 */
public class ConvenientTelephoneActivity extends BaseActivity implements AdapterView.OnItemClickListener {
    @BindView(R.id.tel_type_list)
    protected GridView telTypeList;

    private ConvenientTelAdapter adapter;
    private List<ConvenientTelTypeBean> dataList = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        new TitleUtils(this).setBackVisible(true).useAndSetTxTitle("隆昌便民电话");
        adapter = new ConvenientTelAdapter(this);
        telTypeList.setAdapter(adapter);
        telTypeList.setOnItemClickListener(this);
        getTelData();
    }

    @Override
    protected void initInject() {
        setContentView(R.layout.activity_convenient_telephone);
        ButterKnife.bind(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
    }


    private void getTelData() {
        showProgress("正在加载...");
        Map<String, Object> param = new ArrayMap<>();
        param.put("siteNumber", Constances.SITE_ID);
        NetUtils.getNetAdapter().getConvenienceIntitutionList(getOwnerName(), param, new AbsNetCallBack<TelephoneTypeVo>(TelephoneTypeVo.class) {
            @Override
            public void onSuc(TelephoneTypeVo telephoneTypeVo) {
                if (null != telephoneTypeVo && ListUtils.isListValued(telephoneTypeVo.getInstitutionList())) {
                    dataList.addAll(telephoneTypeVo.getInstitutionList());
                    adapter.setDatas(dataList);
                }
            }

            @Override
            public void onError(Throwable ex, String errorMsg) {
                super.onError(ex, errorMsg);
                toast("数据异常");
            }

            @Override
            public void onEnd() {
                super.onEnd();
                closeProgress();
            }
        });

    }


    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        ConvenientTelTypeBean bean = dataList.get(position);
        Intent intent = new Intent(this, TelephoneListActivity.class);
        intent.putExtra(TelephoneListActivity.TEL_TYPE_ID, bean.getInstitutionId());
        startActivity(intent);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }


}
